<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>

  <script src="node_modules/@babel/standalone/babel.js"></script>
  <script src="node_modules/react/umd/react.development.js"></script>
  <script src="node_modules/react-dom/umd/react-dom.development.js"></script>
  <script type="text/babel">
    // 组件类必须继承自React.Component
      class MyCom extends React.Component{
        constructor(){
          super()
          // state类似vue中的data
          this.state={
            message:"hello im a component"
          }
        }
        render(){ 
          return (
            <div>
              <h1>{this.state.message}</h1>
              {/*组件状态*/}
              <button onClick={this.handleClick}>this</button>
              <button onClick={this.handleClick.bind(this)}>change message</button>
              <button onClick={()=>{console.log(this)}}>change message</button>
              <button onClick={(e)=>{console.log(e.target)}}>change message</button>
              </div>
          )
        }
        handleClick(){
         console.log(this)
         this.setState({
           message:"newnewenwenwewen"
         })
        }
      }
      const element=<MyCom/>
      ReactDOM.render(element,document.getElementById('app'))
    </script>
</body>

</html>